package demo6;

class Animal{
    public String name;
    public int age;
    public Animal(String name,int age){  // 带有两个参数的构造方法
        this.name = name;
        this.age = age;
    }
    public void eat(){
        System.out.println("吃饭");
    }
}

class Dog extends Animal{
    public Dog(String name ,int age){
        super(name,age);
    }

    @Override
    public void eat() {
        System.out.println("吃狗粮");
    }
}

class Cat extends Animal{

    public Cat(String name ,int age){
        super(name,age);
    }
    @Override
    public void eat() {
        System.out.println("吃猫粮");
    }
}

public class Test {
    public static void func(Animal animal){
        animal.eat();
    }

    public static Animal funciton(String name){
        return new Dog("大黄",2);
    }
    public static void main(String[] args) {
        Animal animal1 = new Dog("黑咯破",1);
        Dog dog = (Dog) animal1;
        func(dog);

        System.out.println("===========================");
        if(animal1 instanceof Cat){
            Cat cat = (Cat) animal1;
            animal1.eat();
        }else{
            System.out.println("false");
        }
    }
}
